// There are several timer APIs in cutil.h with more functions.

#include <stdio.h>
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "stopwatch.h"

cudaEvent_t start, stop; 
float elapsedTime; 

void cuda_stopwatch_start( void )
{
	cudaEventRecord( start, 0 );
	printf("The CUDA stopwatch starts.\n");
}

float cuda_stopwatch_stop( void )
{
	cudaEventRecord( stop, 0 );
	cudaEventSynchronize( stop );

	cudaEventElapsedTime( &elapsedTime, start, stop );

	printf("The CUDA stopwatch stops: %.3f sec.\n", (elapsedTime / 1000) );

	return elapsedTime;
}

void cuda_stopwatch_reset( void )
{
	cudaEventDestroy( start );
	cudaEventDestroy( stop );

	cudaEventCreate(&start);
	cudaEventCreate(&stop);

	printf("The CUDA stopwatch has been reset.\n");
}

void cuda_stopwatch_init( void )
{
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	printf("The CUDA stopwatch has been initialized.\n");
}

void cuda_stopwatch_destroy( void )
{
	cudaEventDestroy( start );
	cudaEventDestroy( stop );
	printf("The CUDA stopwatch has been destroyed.\n");
}
